# -*- coding:UTF-8 -*-#

'''
@author: qianwp
'''

import threading
import time

class Singleton(object):

    objs  = {}
    objs_locker =  threading.Lock()

    def __new__(cls, *args, **kv):
        if cls in cls.objs:
            return cls.objs[cls]['obj']

        cls.objs_locker.acquire()
        try:
            if cls in cls.objs: ## double check locking
                return cls.objs[cls]['obj']
            obj = object.__new__(cls)
            cls.objs[cls] = {'obj': obj, 'init': False}
            setattr(cls, '__init__', cls.decorate_init(cls.__init__))
        finally:
            cls.objs_locker.release()
        return cls.objs[cls]['obj']

    @classmethod
    def decorate_init(cls, fn):
        def init_wrap(*args):
            if not cls.objs[cls]['init']:
                fn(*args)
                cls.objs[cls]['init'] = True
            return

        return init_wrap

class ModelType:
    Customer = 0 #普通用户
    Designer = 1 #设计师
    Album = 2 #作品集
    Composit = 3 #作品
    Photo = 4 #作品图片
    Comment = 5 #评论
    Tracker = 6 #关注关系
    Dangler = 7 #被关注关系
    Interester = 8 #收藏关系
    Session = 9 #用户会话 不存库
    
class DigitType:
    Customer = 0
    Compst = 1

class UUIDModel(object):
    
    def mtype(self):
        raise NotImplementedError
    
class DigitModel(object):
    
    def __init__(self):
        self.onmodify()
    
    def onmodify(self):
        self.mtime = time.time()
        self.clean = False
    
    def dtype(self):
        raise NotImplementedError
    
    def custid(self):
        raise NotImplementedError
    
    def update(self):
        raise NotImplementedError
    
    def load(self):
        raise NotImplementedError
        
